{% extends 'base/base.html' %}

{% load myfilter %}

{% block css %}
<style>
    a, a:visited {
        color: #2f468f;
        text-decoration: none;
        position: static;
    }
    ol{
        float:left;
        font-weight:bold;
    }
    .fr{
        float:right;
    }
    h2{
        margin:0;
        text-align:center;
    }
</style>
{% endblock %}


{% block title %}
<title>详情页</title>
{% endblock %}


{% block body %}
<!--跨站请求验证-->
{% csrf_token %}
<div class="bdtop"></div>
<ol class="breadcrumb" style="background-color:white">
  <li><a href="{% url 'main:index' %}">首页</a></li>
  <li class="active">{{ cl2.name }}详情页</li>
</ol>
<dt>
    <p class="fr">
        {% if request.user.is_authenticated and bk2|has_add_mybookshelf:request.user %}
        <a class="collect" rel="nofollow" href="Javascript:void(0);">移出书架</a> |
        {% else %}
        <a class="collect" rel="nofollow" href="Javascript:void(0);">加入书架</a> |
        {% endif %}
        <a class="mybookshelf" rel="nofollow" href="{% url 'operate:collect' %}">我的书架</a>
    </p>
</dt>
<div class="clear"></div>

<h2>这是《{{ cl2.name }}》的详情页</h2>

{% endblock %}

{% block js %}
<script>
    $(function(){
        $(".collect").click(function(){
           if ("{{ request.user.id }}" == "None"){
                location.href = "/user/login?next=/detail/{{ bk2.id }}"
                return ;
           }
            $.ajax({
                // post请求中url末尾的斜杠不能省略
                url: "/operate/add_book/",
                method: "post",
                data: {
                    "csrfmiddlewaretoken": $("[type='hidden']").val(),
                    "book_id": "{{ bk2.id }}"
                },
                success:function(data){
                console.log(data.data.state)
                    if(data.data.state){
                        $(".collect").text("移出书架")
                    }
                    else{
                        $(".collect").text("加入书架")
                    }
                }
            })


        })
    })
</script>
{% endblock %}

